package com.darwin.darwinDll.analyze
{
	import com.darwin.darwinDisplay.DarBitmapData;
	import com.darwin.darwinDll.analyze.IAnalyze;
	import com.darwin.darwinDll.core.DllItem;
	import com.darwin.darwinImage.dar.Dar;
	
	import flash.utils.ByteArray;
	import flash.utils.Dictionary;

	/**
	 * *.dar文件解析器 
	 * @author vanCopper
	 * 
	 */
	public class DarAnalyze implements IAnalyze
	{
		private var _darwinBitmapDataDic:Dictionary;
		private var _darwinFuncDic:Dictionary;
		public function DarAnalyze()
		{
			super();
			_darwinBitmapDataDic = new Dictionary();
			_darwinFuncDic = new Dictionary();
		}
		
		public function getDataList():Dictionary
		{
			return _darwinBitmapDataDic;
		}
		
		
		public function analyze(byteArray:ByteArray, dllItem:DllItem, compFn:Function):void
		{
			if(byteArray)
			{
				dllItem.data = byteArray;
				var arr:Array = Dar.decode(byteArray);
				for (var i:int = 0; i < arr.length; i++) 
				{
					var darwinBitmapData:DarBitmapData = arr[i]; 
					_darwinBitmapDataDic[darwinBitmapData.key] = darwinBitmapData; 
				}
			}
			if(compFn != null)
			{
				compFn(dllItem);
			}
		}
		/**
		 * 获取dar文件 返回DarBitmapData类型 
		 * @param key
		 * @param subKey
		 * @return 
		 * 
		 */		
		public function getData(key:String, subKey:String):*
		{
			var skey:String = key + "_" + subKey;
			return _darwinBitmapDataDic[skey];		
		}
	}
}